package com.efast.dmom.mgmt.controller.mes;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.efast.cafe.framework.bean.ResultBean;

import com.efast.dmom.mgmt.entity.mes.PrBasPrintVinLabel;
import com.efast.dmom.mgmt.service.mes.PrBasPrintVinLabelService;

@Controller
@RequestMapping("/Print")
public class PrBasPrintVinLabelController {
	@Autowired
	PrBasPrintVinLabelService prBasPrintVinLabelService;

	PrBasPrintVinLabel prBasPrintVinLabel = new PrBasPrintVinLabel();

	@RequestMapping(value = "/savePrintInfo")
	public @ResponseBody ResultBean savePintInfo() {

		ResultBean result = new ResultBean(true, "'");
		prBasPrintVinLabelService.printVinLabel("121212", "M01", "Red", "VINLABEL_BIW", true);
		return result;

	}

	@RequestMapping(value = "/printPartNoInfo")
	public @ResponseBody ResultBean printPartNoInfo(@RequestBody PrBasPrintVinLabel labelInfo) throws Exception {
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		Boolean isSequence = labelInfo.getIsSequence();
		String printStatu = labelInfo.getPrintStatu();
		labelInfo.setPrintType("PART_LABEL");

		if (printStatu.equals("1")) {
			if (isSequence) {
				labelInfo.setPrintStatus(false);
				ResultBean resultBean = prBasPrintVinLabelService.printPartNoLabelList(labelInfo);
				if (!resultBean.success) {
					result.setMessage(resultBean.message);
					result.setSuccess(false);
				}
			} else {
				labelInfo.setPrintStatus(true);
				ResultBean resultBean = prBasPrintVinLabelService.printPartNoLabel(labelInfo);
				if (!resultBean.success) {
					result.setMessage(resultBean.message);
					result.setSuccess(false);
				}
			}
		} else {
			labelInfo.setPrintStatus(false);
			ResultBean resultBean = prBasPrintVinLabelService.printPartNoLabel(labelInfo);
			if (!resultBean.success) {
				result.setMessage(resultBean.message);
				result.setSuccess(false);
			}
		}
		return result;

	}

	@RequestMapping(value = "/printVinLabel")
	public @ResponseBody ResultBean printVinLabel(@RequestBody PrBasPrintVinLabel labelInfo) throws Exception {
		ResultBean result = new ResultBean(true, "");
		result.setSuccess(true);
		String printStatu = labelInfo.getPrintStatu();
		labelInfo.setPrintType("VIN_LABEL");
		if (printStatu.equals("1")) {
			labelInfo.setPrintStatus(true);
			ResultBean resultBean = prBasPrintVinLabelService.printVinLabel(labelInfo);
			if (!resultBean.success) {
				result.setMessage(resultBean.message);
				result.setSuccess(false);
			}
		} else {
			labelInfo.setPrintStatus(false);
			ResultBean resultBean = prBasPrintVinLabelService.printVinLabel(labelInfo);
			if (!resultBean.success) {
				result.setMessage(resultBean.message);
				result.setSuccess(false);
			}

		}

		return result;

	}
}
